<template>
	<view class="body">
		
		<view class="line" ></view>
		
		<view class="content" >
			<view>
				<text v-if=" type == '1' " >可</text>
				{{navigationTit}}金额
				<text v-if=" type == '1' " style="padding-left: 20rpx;" >¥{{balence}}</text>
			</view>
			<view class="input-view" >
				<span class="money" >¥</span>
				<input v-model="amount" placeholder="输入自定义金额"  />
			</view>
		</view>
		
		<view>
			<button class="payBtn" @click="submitAction" >{{navigationTit}}</button>
		</view>
		
	</view>
</template>

<script>
	export default{
		
		data(){
			return{
				type: 0   ,//1是提现，2是充值
				balence: 0  ,//余额
				navigationTit: "付款"  ,//导航栏文字
				amount: ""   //输入的金额
			}
		},
		onLoad(options) {
			if(options.type != undefined){
				this.type = options.type
				
				switch(this.type){
					case '2':	//普通用户
					this.navigationTit = '充值'
					break
					case '1':	//商铺
					this.navigationTit = '提现'
					break
					default:
					break
				}
			}
			if(options.balence != undefined){
				this.balence = options.balence
			}
		},
		onReady() {
			
			uni.setNavigationBarTitle({
				title: this.navigationTit
			})
		},
		methods:{
			
			submitAction(){  //提交Action
				if(this.type == '2'){  //充值
					this.topUp()
				}else if(this.type == '1'){  //提现
					this.withdrawal()
				}
			},
			topUp(){ //充值
				// wechatpay  微信
				this.$https.Mine.applyCharge('member',this.amount).then(req => {
					console.log('充值金额如下',req)
					// uni.navigateBack()
					this.callWechat(req)
				})
			},
			withdrawal(){ // 提现
				
				this.$https.Mine.applyWithdraw('member',this.amount).then(req => {
					console.log('提现结果req',req)
					uni.showToast({
						title: '提现审核中',
						icon: 'none',
						duration: 500
					})
					
					setTimeout(function(){
						uni.navigateBack()
					}, 500)
					
				})
			},
			
			//吊起微信
			callWechat(req){
				uni.requestPayment({
					provider: 'wxpay',
					timeStamp: req.timeStamp,
					nonceStr: req.nonceStr,
					package:  req.package,
					signType: req.signType,
					paySign: req.paySign,
					success(req) {
						console.log('是否调用成功',req)
						uni.navigateBack()
					},
					fail(error) {
						console.log('微信支付调用失败',error)
						uni.showToast({
							title: '支付失败',
							icon: "none"
						})
					}
				})
			}
			
		}
	}
	
</script>

<style lang="scss" scoped >
	
	.body{
		
		width: 100%;
		height: 100%;
		
	}
	
	.line{
		height: 20rpx;
		background-color: rgb(250,250,250);
	}
	
	.content{
		margin: 30rpx 20rpx;
	}
	
	.input-view{
		display: flex;
		align-items: center;
		margin: 20rpx;
		padding: 20rpx 0;
		
		border-bottom: 1rpx solid $uni-color-error;
		
		.money{
			font-size: $uni-font-size-lg+10rpx;
			font-weight: bold;
		}
		
		input{
			margin-left: 20rpx;
			
			font-size: $uni-font-size-lg;
		}
	}
	
	.payBtn{
		
		margin: 80rpx 30rpx;
		padding: 8rpx 0;
		
		font-size: $uni-font-size-base;
		background-color: $uni-color-error;
		color: #FFFFFF;
		
		
	}
	
	button::after{
		border: none;
	}
	
</style>
